from django.db import models
from django.db.models.signals import pre_delete, post_delete
from django.dispatch.dispatcher import receiver
from django.utils.translation import ugettext_lazy as _

from apps.accounts.models.users import User

# Create your models here.

class CarouselContent(models.Model):
    '''
    首页轮播图
    '''
    title_zh = models.CharField(max_length=128)
    title_en = models.CharField(max_length=128)
    description_zh = models.TextField(max_length=512)
    description_en = models.TextField(max_length=512)
    picture = models.ImageField(upload_to='_img/%Y/%m/%d/')
    published = models.BooleanField(default=False)
    pub_date = models.DateField(auto_now=True)

    class Meta:
        verbose_name = _('Carousel Content at Home Page')
        verbose_name_plural = _('Carousel Contents at Home Page')

    def __str__(self):
        return self.title_zh

    def get_content(self, lang):
        if lang.startswith('zh'):
            return {'title': self.title_zh,
                    'description': self.description_zh,
                    'picture': self.picture}
        else:
            return {'title': self.title_en,
                    'description': self.description_en,
                    'picture': self.picture}